<!--  -->
<template>
  <div class="">
    1用 JavaScript实现一个数组合并的方法（要求去重）
  </div>
</template>

<script setup lang="ts">

import { } from 'vue';
const b = [1, 1, 3, 4, 5, 2, 3, 5, 4, { name: 'name' }, [{ age: 20 }, 144], [34235223]];
const a = [1, 2, 3, 4, 6, 999, { name: 'name' }, [{ age: 20 }, 144]];
console.log('数组合并的方法（要求去重）', quchong(a, b));

// const promise = new Promise((resolve,reject)=>{
//   return resolve({name: 222})
// })
function quchong(a, b) {
  //console.log(await promise);

  const arr = Array.from(new Set([...a, ...b]));
  return arr.reduce((pre, cur) => {
    const data = pre.find((it) => JSON.stringify(it) === JSON.stringify(cur));
    if (!data) {
      pre.push(cur);
    }
    return pre;
  }, []);
}

const flattenArr = [1, 3, [24, 35, { a: 134 }, [100, 999, { age: 20 }]]];

function flatten(arr) {
  let result = [];
  for (let i = 0; i < arr.length; i++) {
    if (Array.isArray(arr[i])) {
      result = result.concat(flatten(arr[i]));
    } else {
      result = result.concat(arr[i]);
    }
  }
  return result;
}
console.log('flatten', flatten(flattenArr));

</script>

<style lang="scss" scoped></style>
